<?php
/* 
 * 框架表单组件
 */
class FWForm{
    private $_action_url = '';
    private $_coms = array();
    private $_attributes = array();

    function  __construct($controller,$action,$params = null) {
//        Kernel::import($str_import);
        $this->_action_url = Kernel::url($controller, $action,$params);
        $this->_attributes['method'] = 'post';
    }

    function setAttribute($name,$value){
        $this->_attributes[$name] = $value;
    }
    
    function setAttributes($attrs){
        $this->_attributes = array_merge($this->_attributes,$value);
    }
    
    public function addCom($com){
        array_push($this->_coms,$com);
    }

    public function output(){
        $output = '<form ';
        foreach($this->_attributes as $attr_name => $attr_value){
            $output .= "{$attr_name}=\"{$attr_value}\" ";
        }
        $output .= "action=\"{$this->_action_url}\" >\n";
        foreach($this->_coms as $com){
            foreach($com as $n => $v){
                $output .= "<{$n} ";
                foreach($v as $n1 => $v1){
                    $output .= "{$n1}=\"{$v1}\" ";
                }
                $output .= "></{$n}>\n";
            }
        }
        $output .= "</form>";
        return $output;
    }
}
?>